package com.acyouzi.leetcode.dp;

/**
 * 17/9/26 22:10
 *
 * @author sunxu
 */
public class UniqueSubstringsWraparound {
//  https://leetcode.com/problems/unique-substrings-in-wraparound-string/discuss/
  public int findSubstringInWraproundString(String p) {
    int[] dp = new int[26];
    int len = 0;
    for (int i = 0; i < p.length(); i++) {
      // 往前找连续的有几个连续的就有几种可能
      // dp, 有多种角度，从后往前或者从前往后
      if (i > 0 && (p.charAt(i) - p.charAt(i - 1) == 1 || (p.charAt(i - 1) - p.charAt(i) == 25))){
        len++;
      }else len = 1;
      int index = p.charAt(i) - 'a';
      dp[index] = Math.max(dp[index],len);
    }
    int sum = 0;
    for (int i : dp) sum+=i;
    return sum;
  }
}
